package cmd

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
	"websocket/internal/driver"
	"websocket/internal/router"
	"websocket/utility"
)

var (
	Main = gcmd.Command{
		Name:  "websocket",
		Usage: "websocket",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			//g.SetDebug(true)
			s := g.Server()
			s.EnableAdmin()
			s.Group("/", func(group *ghttp.RouterGroup) {
				router.BindController(group)
			})
			Init(ctx)
			s.Run()
			return nil
		},
	}
)

func Init(ctx context.Context) {
	driver.Init()
	utility.IdGenerator.Init(g.Config().MustGet(ctx, "idGenerator.workId").Uint16())
}
